/*
 * Copyright (C) 2017 Fabian Terhorst
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file kt in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.fabianterhorst.isometric.shapes;

import io.fabianterhorst.isometric.Path;
import io.fabianterhorst.isometric.Point;
import io.fabianterhorst.isometric.Shape;

/**
 * Stairs Class.
 *
 * @since 03.03.21
 */
public class Stairs extends Shape {
    private static final int ONE = 1;

    /**
     * Constructor
     *
     * @param origin {@link Point}
     * @param stepCount {@link double}
     */
    public Stairs(Point origin, double stepCount) {
        Path[] paths = new Path[(int) stepCount * 2 + 2];
        Path zigzag = new Path();
        Point[] points = new Point[(int) stepCount * 2 + 2];
        points[0] = origin;
        int i;
        int count = ONE;
        for (i = 0; i < stepCount; i++) {
            Point stepCorner = origin.translate(0, i / stepCount, (i + 1) / stepCount);
            paths[count - 1] = new Path(new Point[] {
                stepCorner, stepCorner.translate(0, 0, -1 / stepCount), stepCorner.translate(1, 0, -1 / stepCount),
                stepCorner.translate(1, 0, 0)
            });
            points[count++] = stepCorner;
            paths[count - 1] = new Path(new Point[] {
                stepCorner, stepCorner.translate(1, 0, 0), stepCorner.translate(1, 1 / stepCount, 0),
                stepCorner.translate(0, 1 / stepCount, 0)
            });
            points[count++] = stepCorner.translate(0, 1 / stepCount, 0);
        }
        points[count] = origin.translate(0, 1, 0);
        zigzag.setPoints(points);
        paths[count++ - 1] = zigzag;
        paths[count - 1] = zigzag.reverse().translatePoints(1, 0, 0);
        setPaths(paths);
    }
}